/**
 * Created by sunkejun on 2015/10/15.
 */


$(document).ready(function(){
    FeManger.init();
})

var FeManger  = (function ($) {
    //...
    return {

        chosefile:function(target,file){

            //console.log(  $("#file_ul_list li a"));
            $("#file_ul_list li a").each(function(){
                    //console.log(this);
                    $(this).css("color","#666666");
                }
            );
            $(target).css("color","red");

            $('#code_path').val(file);
            ComdataUtil.ajaxpostnormal("/admin/file_edit/getfile",{file:file},function(data){
                $('#code').val(data);
                FeManger.$editor.setValue(data);
                FeManger.$editor.refresh()
            },'post');
        },
        init:function(){

            var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
                lineNumbers: true,
                matchBrackets: true,
                styleActiveLine: true,
            });
            //editor.setSize(this.width, 300);
            this.$editor = editor;


        },
        saveSubmit: function () {
            //console.log(this.$editor.getValue());
            if($("#code_path").val() == ""){
                openToastr.open(3,language.getNorlanguage().file_no_chose);
                return;
            }
            ComdataUtil.ajaxpost("/admin/file_edit",{file:$("#code_path").val(),value:FeManger.$editor.getValue()},function(data){
                if(data.code == 500){
                    openToastr.open(3,data.res_data);
                }
            });

        }
    }
})(jQuery);